# from time import sleep
from appium import webdriver
#
# from page.page_daily_task import PageTask
#
# cap = {
#     "platformName": "Android",
#     "platformVersion": "10",
#     "deviceName": "HJS0218B27006432",
#     "appPackage": "com.android.settings",
#     "appActivity": ".HWSettings",
#     "recreateChromeDriverSessions": True,
# }
#
# driver = webdriver.Remote("http://192.168.1.28:4723/wd/hub", cap)
#
# driver.install_app(r"D:\cidao_com.izaodao.cd.apk")
# # PageTask(driver).pagetask_install_cidao_app()...
import sys
from time import sleep
import threading
import paramiko
import re
#创建SSH对象
def test1():
    ssh = paramiko.SSHClient()

    # 允许连接不在know_hosts文件中的主机
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)

    # 连接服务器
    ssh.connect(hostname='192.169.1.52',port=2233,username='test',password='123456')
    # 执行命令

    # stdin,stdout,stderr = ssh.exec_command(r'scrcpy -r D:\112.mp4')
    channel = ssh.invoke_shell()
    channel.send(r'scrcpy -r D:\pytest_video\112.mp4'+'\n')
    # 获取命令结果
    # result = stdout.read().decode('gbk')


#
test1()
cap = {
    "platformName": "Android",
    "platformVersion": "10",
    "deviceName": "HJS0218B27006432",
    "appPackage": "com.izaodao.gps",
    "appActivity": ".activity.SplashActivity",
    "recreateChromeDriverSessions": True
}

driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", cap)
driver.implicitly_wait(10)
input('qing')
driver.find_element_by_accessibility_id('我的').click()
driver.find_element_by_id('com.izaodao.gps:id/tvMeUserName').click()
try:
    driver.find_element_by_id("com.izaodao.gps:id/authsdk_switch_view").click()
except:
    pass
driver.find_element_by_xpath('//android.view.View[@content-desc="密码登录"]').click()
driver.find_element_by_xpath('//android.widget.EditText[@text = "请输入您的手机/邮箱/用户名"]').send_keys('11100009001')
driver.find_element_by_xpath('//android.widget.EditText[@text = "请输入密码"]').send_keys('123456')
driver.find_element_by_xpath('//android.view.View[@content-desc="确定"]').click()
try:
    assert driver.find_element_by_xpath('//android.widget.TextView[@text = "测试号9001"]')
    print('登录成功')
except Exception:
    print('登录失败')
    raise

def test2():
    ssh = paramiko.SSHClient()

    # 允许连接不在know_hosts文件中的主机
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)

    # 连接服务器
    ssh.connect(hostname='192.169.1.52', port=2233, username='test', password='123456')
    stdin1,stdout1,stderr1 = ssh.exec_command('taskkill /IM scrcpy.exe')
    # 获取命令结果
    result = stdout1.read().decode('gbk')
    print(result)
    sleep(5)

    stdin2,stdout2,stderr2 =ssh.exec_command(r'net use \\192.168.1.28\ipc$ "123456" /user:zaodao')
    result = stdout2.read().decode('gbk')
    print(result)
    stdin3,stdout3,stderr3 =ssh.exec_command(r'xcopy D:\112.mp4 \\192.168.1.28\shared /Y')
    result = stdout3.read().decode('gbk')
    print(result)
    stdin4,stdout4,stderr4 =ssh.exec_command(r'net use \\192.168.1.28\ipc$ /delete')
    result = stdout4.read().decode('gbk')
    print(result)
    sleep(3)
test2()
if __name__ == '__main__':
    test1()